var app=new Vue({
    el: '#app',
    data:{
        task:{},
        isDisabled: false,
        dicts:{
            taskType: [],
            taskStatus: []
        },
        taskRules: {
            jobName: [
                { required: true,min: 2, max: 12, message: '任务名称长度在 2 到 12 个字符', trigger: 'blur' }
            ],
            jobGroup: [
                { required: true,min: 2, max: 12, message: '任务分组长度在 2 到 12 个字符', trigger: 'blur' }
            ],
            cron: [
                {  required: true, message: '请填写cron表达式', trigger: 'blur' }
            ],
            beanClass: [
                {required: true,  message: '请填写包名.类名', trigger: 'blur' }
            ],
            taskStatus: [
                { required: true, message: '请至少选择一个任务状态', trigger: 'change' }
            ],
            taskType: [
                { required: true, message: '请至少选择一个任务类型', trigger: 'change' }
            ],
            remark: [
                { max:100, message: '备注最大长度为100', trigger: 'blur' }
            ]
        }
    },
    methods:{
        init: function(){
            var _this=this;
            setTimeout(function(){
                _this.initDict();
            },100);
        },
        closeDialog: function(){
            jsmile.dialog.close();
        },
        insertTask: function(){
            var _this=this;
            _this.isDisabled=true;
            this.$refs['task'].validate(function(valid){
                if (valid) {
                    jsmile.http.sendJson({
                        url:jsmile.url+"/sys/task/save",
                        data:_this.task
                    }).done(function(res){
                        jsmile.msg.success("添加任务成功");
                        jsmile.dialog.close();
                        top.$('#home')[0].contentWindow.app.query();
                    }).fail(function(res){
                        jsmile.msg.error(res.resMsg?res.resMsg:"添加任务失败!");
                    });
                } else {
                    return false;
                }
            });
        },
        /**
         * 初始化数据字典
         */
        initDict: function(){
            var _this=this;
            var s=jsmile.copy([],jsmile.dict.zt);
            _this.dicts.taskStatus=s;

            jsmile.http.sendJson({
                url:jsmile.url+"/sys/dict/findDictByCode",
                data:{"dictCode":"TK01"}
            }).done(function(res){
                _this.dicts.taskType=res.resData;
            });
        }
    }
});
$(function(){
    init();
    function init(){
        app.init();
    }
});